package top.zhangjianyong.tools.service.mybatis.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.tomcat.jni.Local;
import org.springframework.stereotype.Service;
import top.zhangjianyong.tools.entity.HotVideo;
import top.zhangjianyong.tools.mapper.HotVideoMapper;
import top.zhangjianyong.tools.service.mybatis.IHotVideoService;

import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalUnit;
import java.util.List;

/**
 * @author ： zhangjianyong
 * @date ： 2023/3/6 3:47 PM
 */
@Service
public class IHotVideoServiceImpl extends ServiceImpl<HotVideoMapper, HotVideo> implements IHotVideoService {


    @Override
    public HotVideo qryByTitleAuthor(HotVideo hotVideo) {
        return lambdaQuery().eq(HotVideo::getTitle, hotVideo.getTitle())
                .eq(HotVideo::getAuthor, hotVideo.getAuthor())
                .one();
    }

    @Override
    public List<HotVideo> listByCreate(LocalDate date) {

        return lambdaQuery()
                .between(HotVideo::getCreateTime, date.atStartOfDay(), date.plusDays(1))
                .orderByDesc(HotVideo::getHotValue)
                .list();
    }

    @Override
    public boolean watch(Long videoId, Integer watchFlag) {
        return lambdaUpdate().eq(HotVideo::getId, videoId)
                .set(HotVideo::getWatchFlag, watchFlag)
                .update();
    }

    @Override
    public List<HotVideo> listLimit(int limit) {
        return lambdaQuery()
                .orderByAsc(HotVideo::getWatchFlag)
                .orderByDesc(HotVideo::getHotValue)
                .last(" limit "+limit)
                .list();
    }

    @Override
    public List<HotVideo> listUserLimit(Long userId, int limit) {
        return baseMapper.listUserLimit(userId,limit);
    }
}
